<?php
/**
 * Created by PhpStorm.
 * User: Vito
 * Date: 2022/3/30
 * Time: 15:33
 */

namespace app\admin\curd\admin;


use app\common\curd\Update;
use app\common\Enum;
use app\exception\MessageException;
use app\validate\AdminValidate;
use think\Model;

class AdminUpdate extends Update
{
    use AdminTrait;

    //验证器
    protected $validate = [
        AdminValidate::class => Enum::VALID_UPDATE_SCENE,
    ];
    //允许新增的数据字段
    protected $field = ['nickname', 'status', 'password', 'role_id', 'tel', 'email', 'mark', 'disabled_mark'];
    //排除的数据
    protected $exclude = [];
    //条件
    protected $where = [];

    protected function saveMiddleware($next, Model $model, array $params)
    {
        if ($this->isSuperAdmin($model)) {
            throw new MessageException('不可修改该管理员');
        }

        $roleID = $params['role_id'] ?? 0;
        $this->canSetRole($roleID);

        return parent::saveMiddleware($next, $model, $params); // TODO: Change the autogenerated stub
    }
}